package com.framework.log.service.impl;

import com.framework.common.config.SessionUtil;
import com.framework.log.model.SysLog;
import com.framework.log.param.SysLogParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import com.framework.log.mapper.SysLogMapper;
import com.framework.log.repository.SysLogRepository;
import com.framework.log.service.ISysLogService;

import javax.transaction.Transactional;

@Service
public class SysLogService implements ISysLogService{
	@Autowired
    private SysLogMapper baseMapper;
	@Autowired
	private SysLogRepository sysLogRepository;
	
	@Override
	@Transactional(Transactional.TxType.REQUIRES_NEW)
	public SysLog save(SysLog sysLog) {
		sysLog = sysLogRepository.save(sysLog);
		return sysLog;
	}

	@Override
	@Transactional(Transactional.TxType.REQUIRES_NEW)
	public SysLog info(String description, String status) {
		SysLog sysLog = new SysLog();
		sysLog.setDescription(description);
		sysLog.setUsername(SessionUtil.getUser().getName());
		sysLog.setType(status);
		sysLog = save(sysLog);
		return sysLog;
	}

	@Override
	public Page<SysLog> listPage(SysLogParam param) {
		PageRequest pageRequest = PageRequest.of(param.getPageNo(), param.getPageSize());
		return baseMapper.listPage(param, pageRequest);
	}
}
